package data;

import java.util.ArrayList;

/** This contains all the user related
 * DTObjects of the arraylist userList
 * @author Matthias
 *
 */
public class User {

	/** boolean object, false **/
	public boolean toAdmin = false;

	/** int object **/
	private int userID;
	
	/** int object **/
	private int pin;
	
	/** String objects **/
	private String firstName, lastName, streetName, 
	city, streetNr, telephoneNr, zipCode;	
	
	/** Arraylist of Account **/
	private final ArrayList<Account> accountList;
		
	/** Constructor of User
	 * @param userID defines the users id
	 * @param pin defines the users pin
	 * @param firstName defines the users first name
	 * @param lastName defines the users last name
	 * @param telephoneNr defines the users telephone nr
	 * @param streetName defines the users street name
	 * @param streetNr defines the users street nr
	 * @param zipCode defines the users zip code
	 * @param city defines the users city
	 */
	public User (final int userID, final int pin, 
			final String firstName, final String lastName, 
			final String telephoneNr,
			final String streetName, final String streetNr, 
			final String zipCode, final String city) {
		
		this.userID = userID;
		this.pin = pin;
		this.firstName = firstName;
		this.lastName = lastName;
		this.telephoneNr = telephoneNr;
		this.streetName = streetName;
		this.streetNr = streetNr;
		this.zipCode = zipCode;
		this.city = city;
		this.accountList = new ArrayList<Account>();
	}

	/** determines whether a user-specified PIN matches PIN in Account
	 * @param userPIN
	 * @return whether the entered pin is validated
	 */
	public boolean validatePIN (final int userPIN) {
		return userPIN == pin;
	}

	/** Adds an account to the arraylist
	 * @param _account
	 */
	public final void addAccount(final Account _account){
		this.accountList.add(_account);
	}

	/** The method gets access to Account
	 * @param accNr defines the account nr
	 * @return the current account number
	 */
	public final Account getAccount(final int accNr) {
		for (Account number : accountList) {
			if (number.getAccountNumber() == accNr) {
				return number;
			}
		}
		return null;
	}
	
	/**
	 * @param accNr is being removed from the accountlist
	 */
	public final void removeAccount(final int accNr) {
		Account account = getAccount(accNr);
		if (account != null) {
			accountList.removeAll(getAccountList());
		}
	}
	
	/**
	 * @param userID defines the users id
	 * @param pin defines the users pin
	 * @param firstName defines the users first name
	 * @param lastName defines the users last name
	 * @param telephoneNr defines the users telephone nr
	 * @param streetName defines the users street name
	 * @param streetNr defines the users street nr
	 * @param zipCode defines the users zip code
	 * @param city defines the users city
	 */
	public void setNewInfo (final int userID, final int pin, final String firstName,
			final String lastName, final String telephoneNr, final String streetName,
			final String streetNr, final String zipCode, final String city) {
		this.userID = userID;
		this.pin = pin;
		this.firstName = firstName;
		this.lastName = lastName;
		this.telephoneNr = telephoneNr;
		this.streetName = streetName;
		this.streetNr = streetNr;
		this.zipCode = zipCode;
		this.city = city;
	}

	/**
	 * @return the user id
	 */
	public final int getUserID() {
		return userID;
	}

	/**
	 * @return the pin
	 */
	public final int getPIN() {
		return pin;
	}
	
	/**
	 * @return the first name
	 */
	public final String getFirstName() {
		return firstName;
	}
	
	/**
	 * @return the last name
	 */
	public final String getLastName() {
		return lastName;
	}
	
	/**
	 * @return the telephone number
	 */
	public final String getTelephoneNr() {
		return telephoneNr;
	}

	/**
	 * @return the streetName
	 */
	public final String getStreetName() {
		return streetName;
	}

	/**
	 * @return the streetNr
	 */
	public final String getStreetNr() {
		return streetNr;
	}

	/**
	 * @return the zipCode
	 */
	public final String getZipCode() {
		return zipCode;
	}
	
	/**
	 * @return city
	 */
	public final String getCity() {
		return city;
	}

	/** Method used to get access to the arraylist accountlist
	 * @return accountList
	 */
	public final ArrayList<Account> getAccountList() {
		return accountList;
	}
	
	/**
	 * @return false
	 */
	public final boolean isToAdmin() {
		return toAdmin;
	}
	
	/** Converts accountList to an array, containing the suitable data
	 *  used for both the JComboBox of ChoiceAcc and UserMenuDelete
	 * @return an converted array of Strings from the accoutList
	 */
	public final String[] getAccountChanger(){
		String info[] = new String[accountList.size()];
	    for (int i = 0; i < accountList.size(); i++) {
	    	info[i] = "<html><p>Account: " + accountList.get(i).getAccountNumber() 
	    			+ " - " + accountList.get(i).getAccountType()
					+ " <br> Balance: " + accountList.get(i).getTotalBalance() + "<hr></p></html>";
		}
	    return info;
	}
	
} // end User class